package salesforce;

import java.util.Stack;

public class ReverseStack {
    private void pushToBottom(Stack<Integer> stack, Integer n) {
        if (stack.isEmpty()) {
            stack.push(n);
        }else {
            int val = stack.pop();
            pushToBottom(stack, n);
            stack.push(val);
        }
    }

    public void reverseStack(Stack<Integer> stack) {
        if (!stack.isEmpty()) {
            int n = stack.pop();
            reverseStack(stack);
            pushToBottom(stack, n);
        }
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack);
        new ReverseStack().reverseStack(stack);
        System.out.println(stack);
    }
}
